package com.da.lon.wang.xlg.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;

import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.constants.PreferencesConfig;
import com.da.lon.wang.xlg.constants.XLGConstants;
import com.da.lon.wang.xlg.util.PreferenceUtils;
import com.da.lon.wang.xlg.util.Utils;
import com.da.lon.wang.xlg.util.WebViewUtil;
import com.da.lon.wang.xlg.util.WebViewUtil.OnLoading;
import com.umeng.analytics.MobclickAgent;

public class OneFragment extends BaseFragment {

    private WebView webView;
    private WebViewUtil webViewUtil;
    private String product_number;
    private View view;
    private Context context;
    private LinearLayout goods_detale_ll;

    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("OneFragment");
        MobclickAgent.onResume(getActivity());
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("OneFragment");
        MobclickAgent.onPause(getActivity());
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected View inflateView(LayoutInflater inflater, ViewGroup var2) {
        // TODO Auto-generated method stub
        view = inflater.inflate(R.layout.ouka_one_fragment, null);
        return view;
    }

    @Override
    protected void initView() {
        // TODO Auto-generated method stub
        product_number = PreferenceUtils.getInstance().getSettingStr(
                PreferencesConfig.PRODUCT_NUMBER, "");

        initView(view);
    }

    private void initView(View view) {
        try {
            goods_detale_ll = (LinearLayout) view
                    .findViewById(R.id.goods_detale_ll);
            webView = new WebView(getActivity());
            webView.getSettings().setUseWideViewPort(true);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setBuiltInZoomControls(false);
            webView.loadUrl(Utils.constructUrl(XLGConstants.WEB_URL + "p/"
                    + product_number + ".html?viewtype=1&"));
            webViewUtil = new WebViewUtil(context);
            MyApplication.getWebViewUtil().setWebView(
                    Utils.constructUrl(XLGConstants.WEB_URL + "p/"
                            + product_number + ".html?viewtype=1&"), null,
                    webView, 0);
            MyApplication.getWebViewUtil().setOnloadingListener(
                    new OnLoading() {

                        @Override
                        public void onStart(String url) {
                        }

                        @Override
                        public void onGetLocation(String url) {
                        }

                        @Override
                        public void onError() {
                        }

                        @Override
                        public void onComplete(String url) {
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        // webView.stopLoading();
        view = null;
    }

    @Override
    protected void RefreshData() {
        // TODO Auto-generated method stub

    }

}
